package generics.rawtype;

import org.junit.Test;

import java.util.*;

public class GerecicsMethod {

    public static  <T extends Comparable<? super T>> T max(List<? extends  T> list) {
        Iterator<? extends T> i = list.iterator();
        T result = i.next();
        while (i.hasNext()) {
            T t = i.next();
            if (t.compareTo(result) > 0 ) {
                result = t;
            }
        }
        return  result;
    }

    public static <E> Set<E> Union(Set<E> s1, Set<E> s2) {
        Set<E> result = new HashSet<>(s1);
        result.addAll(s2);
        return  result;
    }
    private static UaryFucntion<Object> IDENTITY_FUNCTION = new UaryFucntion<Object>() {
        @Override
        public Object apply(Object args) {
            return args;
        }
    };
    @SuppressWarnings("unchecked")
    public static <T> UaryFucntion<T> identityFucntion() {
        return (UaryFucntion<T>) IDENTITY_FUNCTION;
    }
    interface  UaryFucntion<T> {
        T apply(T args);
    }
    @Test
    public void test() {
        Set<String> guys = new HashSet<>(Arrays.asList("Tome", "Dick"));
        Set<String> stoogs = new HashSet<>(Arrays.asList("Larray", "Jedk"));
        Set<String> result = Union(stoogs, guys);
        System.out.print(result);
    }
}
